#include "sendretshow.h"
#include "ui_sendretshow.h"
#include <qdebug.h>
#include <qstandarditemmodel.h>

enum {
    SEND_IDLE,
    SEND_DEAL,
    SEND_SUCCESS,
    SEND_FAIL
};

sendretshow::sendretshow(QHash<QString,DEV> dev,QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::sendretshow)
{
    ui->setupUi(this);

    QHash<QString, DEV>::iterator i;
    int j  = 0;

    QStandardItemModel* model = new QStandardItemModel();
//    QStringList labels = QObject::trUtf8(" DEVICEID ,  STATUS  ").split(",");
//    model->setHorizontalHeaderLabels(labels);
    model->setColumnCount(2);
    model->setHeaderData(0,Qt::Horizontal,QString("   设 备 号   "));
    model->setHeaderData(1,Qt::Horizontal,QString("   状    态   "));
     //定义item
     QStandardItem* item = 0;

     qDebug() << "遍历哈希表如下-------------" << endl;
     for(i = dev.begin(); i != dev.end(); ++i,j++) {
         qDebug() << i.key() <<"        " << i.value().ID << i.value().status;

         item = new QStandardItem(QString("%1").arg(i.value().ID));
         model->setItem(j,0,item);
         if (i.value().status == SEND_SUCCESS)
             item = new QStandardItem(QString("%1").arg("发送成功"));
         if (i.value().status == SEND_FAIL)
             item = new QStandardItem(QString("%1").arg("发送失败"));
         model->setItem(j,1,item);
     }

     ui->tableView->setModel(model);
     ui->tableView->show();
}

sendretshow::~sendretshow()
{
    delete ui;
}
